package com.yanzhu.service.mapper;

import com.yanzhu.service.model.RedPackets;
import com.yanzhu.service.model.mix.RedPacketsDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 15:48 2018/1/29
 * @Modified:
 */
@Mapper
public interface RedPacketsMapper {
    @Insert("insert into red_packets(uid, vid, money, sum, title, remain_sum, remain, red_time) values(#{uid}, #{vid}, #{money}, #{sum}, #{title},  #{remain_sum}, #{remain}, #{red_time})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
    int insert(RedPackets redPackets);

    @Update("update red_packets" +
            "  set remain_sum=remain_sum - #{money}," +
            "  set remain=remain - 1" +
            "  where vid = #{vid}")
    void updateRedPackets(@Param("vid") long vid, @Param("money") float money);

    @Select("select * from red_packets where vid = #{vid}")
    RedPackets queryVideoRedPackets(@Param("vid") long vid);

    @Select("select r.vid, r.money, r.sum, r.remain, r.title, u.nickname, u.avatar" +
            " from red_packets r" +
            " left join user u on u.id = r.uid" +
            " where r.vid = #{vid}")
    RedPacketsDetail queryRedPacketsDetail(@Param("vid") long vid);
}
